const mongoose = require('mongoose')
const mongoosePaginate = require('mongoose-paginate')
const path = require('path')

module.exports = function (db) {
    return db.model(path.basename(__filename, path.extname(__filename)), new mongoose.Schema(
        {
            im_suffix: {   // im 番号后缀
                type: String,
                index: true,
                default: '',
            },

            user_id: {    // socket 注册的用户id
                type: String,
                index: true,
            },

            product: {    // 产品
                type: String,
                index: true,
            },

            socket_id_web : {
                type: String,
                index: true,
            },

            // android 客户端连接
            socket_id_android : {
                type: String,
                index: true,
            },

            // ios客户端连接
            socket_id_ios: {
                type: String,
                index: true,
            },

            //创建时间
            created_at: {
                type: Date,
                index: true,
                default: Date.now
            },

            updated_at: {
                type: Date,
                default: Date.now
            },
        },
        {
            collection: path.basename(__filename, path.extname(__filename)),
            timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }
        }).plugin(mongoosePaginate)
    )
}
